# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=gnutls
pkgname=('gnutls' 'libgnutls' 'libgnutls-devel')
_base_ver=3.6.12
pkgver=${_base_ver}
pkgrel=1
pkgdesc="A library which provides a secure layer over a reliable transport layer"
arch=('x86_64' 'i686')
license=('GPL3' 'LGPL2.1')
url="https://www.gnutls.org/"
makedepends=('gettext-devel'
             'libidn2-devel'
             'libiconv-devel'
             'gmp-devel'
             'libnettle-devel'
             'libp11-kit-devel'
             'libtasn1-devel'
             'libunistring-devel'
             'zlib-devel')
#optdepends=('guile: for use with Guile bindings')
source=(https://gnupg.org/ftp/gcrypt/gnutls/v${_base_ver%.*}/${pkgname}-${pkgver}.tar.xz{,.sig}
        gnutls-3.6.3-msysize.patch)
sha256sums=('bfacf16e342949ffd977a9232556092c47164bd26e166736cf3459a870506c4b'
            'SKIP'
            'e082dee5a087ad0773f9b3e295c9bc18848badcf7061e7a2d6bebcc3294559f8')
validpgpkeys=('0424D4EE81A0E3D119C6F835EDA21E94B565716F'
              '1F42418905D8206AA754CCDC29EE58B996865171')
               # "Simon Josefsson <simon@josefsson.org>"
               # "Nikos Mavrogiannopoulos <nmav@gnutls.org>

prepare() {
  cd "${srcdir}"/${pkgname}-${_base_ver}
  patch -p1 -i ${srcdir}/gnutls-3.6.3-msysize.patch

  autoreconf -vfi
}

build() {
  cd "${srcdir}/${pkgname}-${_base_ver}"
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --disable-guile \
    --enable-cxx \
    --disable-hardware-acceleration \
    --enable-heartbeat-support \
    --with-default-trust-store-file=/usr/ssl/certs/ca-bundle.crt

  make
  make DESTDIR="${srcdir}/dest" install
  rm ${srcdir}/dest/usr/share/info/dir
}

check() {
  cd "${srcdir}"/${pkgname}-${_base_ver}
  #make check
}

package_gnutls() {
  depends=("libgnutls=${pkgver}")

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/
}

package_libgnutls() {
  depends=('gcc-libs' 'libidn2' 'libiconv' 'libintl' 'gmp' 'libnettle' 'libp11-kit' 'libtasn1' 'zlib')
  groups=('libraries')
  install=libgnutls.install

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
}

package_libgnutls-devel() {
  pkgdesc="Libgnutls headers and libraries"
  groups=('development')
  depends=("libgnutls=${pkgver}")

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib/pkgconfig ${pkgdir}/usr/lib/
  cp -f ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib/
}
